package com.yvtian.admin.controller;

import com.yvtian.annotation.Log;
import com.yvtian.entity.Result;
import com.yvtian.entity.StatusCode;
import com.yvtian.enums.OperatorType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("sys")
public class SysConfigController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Log(value = "修改大屏配置", isSave = true, operType = OperatorType.UPDATE)
    @RequestMapping(value = "/setMainConfig", method = RequestMethod.POST)
    public Result setMainConfig(@RequestBody Map<String, Object> reqData) {

        redisTemplate.opsForHash().putAll("MAIN_CONFIG", reqData);

        return new Result(true, "设置成功", StatusCode.OK);
    }

    @RequestMapping(value = "/getMainConfig", method = RequestMethod.GET)
    public Result getMainConfig() {

        Map<Object, Object> mainConfig = redisTemplate.opsForHash().entries("MAIN_CONFIG");

        return new Result(true, "获取成功", StatusCode.OK, mainConfig);
    }
}
